CON

  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000

  SDA_PIN       = 29
  SCL_PIN       = 28
  ACK           = 0
  NAK           = 1

  I2C_STATUS      = $50_50
  I2C_MUTE        = $51_01
  I2C_UNMUTE      = $51_00
  I2C_SHUTDOWN    = $52_52
  I2C_DISABLE_I2C = $53_53
  I2C_RESET_I2C   = $54_54

obj

  i2c   :       "new_i2c"
  d     :       "Parallax Serial Terminal"
     
  
pub go | i, system_status, battery_adc_reading

  'start the serial object for communications back to the PC's serial terminal
  d.start(115_200)              'start comms at 115_200 baud

  PauseMS(2000)                 'wait 2 seconds
  
  d.clear

  'Start the I2C object.  This doesnt do anything other than setup the I/O pins.
  i2c.StartI2C(SDA_PIN, SCL_PIN)
  
  d.str(string("Disableing PSoC I2C Comms", 13))

'=======================================================================================================================================
   
  i2c.SendStart
  i2c.TxByte($EA & !$01)      'Slave Address + Write command
  i2c.TxByte(I2C_DISABLE_I2C)             '<---- First byte to send
  i2c.TxByte(I2C_DISABLE_I2C>>8)          '<---- Second byte to send
   
   
  i2c.SendStart
  i2c.TxByte($EA | $01)      'Slave Address + Read command

  d.str(string("Data back from the I2C bus...", 13))

  repeat 8
    d.hex(i2c.RxByte(ACK), 2)     '<---- Print byte read back
    d.char(13)                    'new line

  d.hex(i2c.RxByte(NAK), 2)     '<---- Print last byte read back

  i2c.SendStop
   

  d.char(13)                    'newline
  d.char(13)                    'newline

  d.str(string("Done"))

'=======================================================================================================================================

   
  



pub PauseMS(Duration)
''  Pause execution for 'duration' milliseconds.
''  This routine is based on the set clock frequency.
''  
''  params:  Duration = number of milliseconds to delay                                                                                               
''  return:  none

  waitcnt((((clkfreq / 1_000) * Duration - 3932) #> 381) + cnt)